
package com.mc.collection;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class RandomString {

    protected final Random rnd;

    public RandomString() {
        this(ThreadLocalRandom.current());
    }

    public RandomString(Random rnd) {
        this.rnd = rnd;
    }

    public String random(int count, char[] chars) {
        if (count == 0) {
            return "";
        } else {
            char[] result;
            for (result = new char[count]; count-- > 0; result[count] = chars[this.rnd.nextInt(chars.length)]) {
            }

            return new String(result);
        }
    }

    public String random(int count, String chars) {
        return this.random(count, chars.toCharArray());
    }


}
